package com.yuyou.fn.service.impl;


import java.util.List;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.mail.EmailException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.yuyou.fn.service.IEmailService;
import com.yuyou.fn.util.EmailUtil;

/**
 * Sms 表数据服务层接口实现类
 */
@Service
public class EmailServiceImpl implements IEmailService {
    @Value("${email.username}")
    private String username;
    @Value("${email.password}")
    private String password;
    @Value("${email.smtp.address}")
    private String smtpAddress;
    @Value("${email.smtp.portssl}")
    private int  smtpPortSSL;
    @Value("${email.from}")
    private String from;

    @Value("${check.token}")
    private String checkToken;

    @Override
    public int sendEmail(String token,String toAddress, String subject, String content,List<String> urls, List<String> names) throws EmailException{

        String s = DigestUtils.md5Hex(toAddress + checkToken);
        System.out.println(token);
        System.out.println(s);
        System.out.println(toAddress);
        System.out.println(checkToken);
        if (s.equals(token)){
            EmailUtil.sendMail(username,password,smtpAddress,smtpPortSSL,from,toAddress,subject,content,urls,names);
            return 0;
        }else {
            return 3;
        }
    }

}